package 力扣_滑动窗口.第三类模板;

import java.util.Arrays;

/**
 * @author zx
 * @create 2022-05-10 18:46
 */
public class 字符串的排列_567 {
    public boolean checkInclusion(String s1, String s2) {
        if(s1.length() > s2.length()){
            return false;
        }
        int windowSize = s1.length();
        int[] arr1 = new int[26];
        int[] arr2 = new int[26];
        for(int i = 0;i < windowSize;i++){
            arr1[s1.charAt(i) - 'a']++;
            arr2[s2.charAt(i) - 'a']++;
        }
        if(Arrays.equals(arr1,arr2)){
            return true;
        }
        int left = 0;
        for(int right = windowSize;right < s2.length();right++){
            arr2[s2.charAt(right) - 'a']++;
            left = right - windowSize;//窗口左值是固定的：right - windowSize
            arr2[s2.charAt(left) - 'a']--;
            if(Arrays.equals(arr1,arr2)){
                return true;
            }
        }
        return false;
    }
}
